/* 
 * Copyright 2013 Sébastien Mouquet.
 * 
 * This file is part of ECovoiturage.
 * 
 * ECovoiturage is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ECovoiturage is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Foobar. If not, see http://www.gnu.org/licenses/.
 */
package com.smouquet.ecovoiturage.core.util;

import static com.google.gwt.thirdparty.guava.common.base.Preconditions.checkArgument;

import java.util.Calendar;

/**
 * Classe offrant des méthodes utilitaires pour les dates.
 * 
 * @author sebastien.mouquet
 */
public class DateUtil
{
    /**
     * Indique si la date transmise correspond à la date du jour.
     * 
     * @param date Date à tester (non null)
     * @return Vrai si la date correspond à la date d'aujourd'hui
     * @throws IllegalArgumentException Si date est null
     */
    public static boolean isToday(Calendar date)
    {
        checkArgument(date != null, "date is required");
        
        
        Calendar ddj = Calendar.getInstance();
        
        return ddj.get(Calendar.DATE) == date.get(Calendar.DATE) &&
               ddj.get(Calendar.MONTH) == date.get(Calendar.MONTH) &&
               ddj.get(Calendar.YEAR) == date.get(Calendar.YEAR);
    }
}
